package com.example.obtaingaode.activity;

import com.blankj.utilcode.util.Utils;
import com.example.obtaingaode.db.MyObjectBox;
import com.example.obtaingaode.di.AppComponent;
import com.example.obtaingaode.di.DaggerAppComponent;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;

import android.app.Application;

import io.objectbox.BoxStore;

public class MyApplication extends Application {
    static MyApplication mApplication;
    static AppComponent mAppComponent;
    static BoxStore boxStore;

    @Override
    public void onCreate() {
        super.onCreate();
        Logger.addLogAdapter(new AndroidLogAdapter());
        Utils.init(this);
        initDagger();
        initBoxStore();
    }

    /**(
     * 初始化boxstore(数据库)
     */
    private void initBoxStore() {
        boxStore= MyObjectBox.builder().androidContext(this).build();
    }

    private void initDagger() {
        mAppComponent = DaggerAppComponent.create();
        mAppComponent.inject(this);
    }

    public MyApplication() {
        mApplication = this;
    }

    public static MyApplication getInstance() {
        return mApplication;
    }

    public static AppComponent getAppComponent() {
        return mAppComponent;
    }

    public static BoxStore getBoxStore() {
        return boxStore;
    }
}
